package com.fortune.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.fortune.vo.mSelect.ProductDisc;
import io.swagger.annotations.ApiImplicitParams;
import org.apache.ibatis.annotations.Param;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fortune.base.BaseAPIExcution;
import com.fortune.constants.Constants;
import com.fortune.dto.excution.MSelectExcution;
import com.fortune.entity.MUserInfo;
import com.fortune.enums.MSelectEnum;
import com.fortune.service.MSelectService;
import com.fortune.vo.mSelect.SelectProduct;
import com.fortune.vo.mSelect.SelectStore;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@Api(value = "mSelect", description = "厂商下拉框数据", tags = {"厂商下拉框数据"})
@RestController
@RequestMapping("mSelect")
@Validated
public class MSelectController {
	@Autowired
	private MSelectService mSelectService;
	
	@ApiOperation(value = "商品列表", nickname = "mSelectProduct", notes = "", tags={ "@曹然" })
	@ApiImplicitParams({
			@ApiImplicitParam(name="dId", value="经销商id",paramType="query",dataType="string"),
			@ApiImplicitParam(name="type", value="排序名",paramType="query",dataType="Integer",allowableValues = "0,1"),
	})
    @GetMapping(value = "products",
            produces = { MediaType.APPLICATION_JSON_VALUE })
	public BaseAPIExcution<List<SelectProduct>> listProducts(HttpServletRequest request, @Validated @NotBlank(message="经销商id不能为空")String dId,@Param("type")Integer type){
		HttpSession session = request.getSession();
		MUserInfo mUserInfo = (MUserInfo) session.getAttribute(Constants.SESSION_M_USER);
		List<SelectProduct> products = mSelectService.listAllMProductss(mUserInfo.getmId(), dId,type);
		return new MSelectExcution<List<SelectProduct>>(MSelectEnum.SUCCESS, products);
	}
	@ApiOperation(value = "厂商仓库列表", nickname = "mSelectStore", notes = "", tags={ "@曹然" })
    @GetMapping(value = "stores",
            produces = { MediaType.APPLICATION_JSON_VALUE })
	public BaseAPIExcution<List<SelectStore>> listStores(HttpServletRequest request){
		HttpSession session = request.getSession();
		MUserInfo mUserInfo = (MUserInfo) session.getAttribute(Constants.SESSION_M_USER);
		List<SelectStore> selectStores = mSelectService.listAllMStores(mUserInfo.getmId());
		return new MSelectExcution<List<SelectStore>>(MSelectEnum.SUCCESS, selectStores);
	}

	@ApiOperation(value = "通过商品查优惠", nickname = "mProductDisc", notes = "", tags={ "@安童" })
	@ApiImplicitParams({
			@ApiImplicitParam(name="proId", value="商品ID",paramType="query",dataType="string"),
	})
	@GetMapping(value = "mProductDisc",
			produces = { MediaType.APPLICATION_JSON_VALUE })
	public BaseAPIExcution<ProductDisc> mProductDisc(HttpServletRequest request,String proId){
		HttpSession session = request.getSession();
		MUserInfo mUserInfo = (MUserInfo) session.getAttribute(Constants.SESSION_M_USER);
		ProductDisc products = mSelectService.findProDisc(mUserInfo.getmId(),proId);
		if(products == null){
			return new MSelectExcution<ProductDisc>(MSelectEnum.PRODUCT_NOT_EXISTS, products);
		}
		return new MSelectExcution<ProductDisc>(MSelectEnum.SUCCESS, products);
	}
}
